package csel.model.entity;

import csel.model.*;
import csel.model.items.*;

import org.apache.log4j.Logger;

public class PlayerCharacter extends Character
{
	private static final long serialVersionUID = 6L;
	
	private static final Logger logger = Logger.getLogger("csel.model");
	
	private final MyBlockNotifier myBlockNotifier;
	
	private Character iCharacter;
	private Vehicle iVehicle;
	
	public PlayerCharacter(Occupation occupation, String name)
	{
		super(occupation, name);
		
		myBlockNotifier = new MyBlockNotifier();
		
		iCharacter = null;
		iVehicle = null;
	}

	@Override
	public int getBuyPrice(Character c, TakeableItem ti)
	{
		return -1;   // players are never bought from (currently)
	}

	@Override
	public int getSellPrice(Character c, TakeableItem ti)
	{
		return -1;   // players are never sold to (currently)
	}

	@Override
	public String talk(Character c)
	{
		return "Just Chattin'";
	}

	@Override
	public void die()
	{
		setCharacterStat(CharacterStats.Damage, getCharacterStat(CharacterStats.MaxLife));
	}

	/* INTERACTION */

	@Override
	public void touch(Entity e)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean touch(UseableItem ui)
	{
		//TODO
		if(iVehicle != null)
		{
			return iVehicle.touch(ui);
		}
		pickUp(ui);
		return true;
	}

	@Override
	public boolean touch(EquippableItem ei)
	{
		//	TODO
		if(iVehicle != null)
		{
			return iVehicle.touch(ei);
		}
		pickUp(ei);
		return true;
	}
	
	public Character getInteractingCharacter()
	{
		return iCharacter;
	}
	
	public Vehicle getInteractingVehicle()
	{
		return iVehicle;
	}
	
	public void stopInteracting()
	{
		iCharacter = null;
		iVehicle = null;
	}

	public void pissTaitOff(Character c)
	{
		System.out.println("SomeoneTriedToStealFromYou");
	}
	
	@Override
	protected BlockNotifier getBlockNotifier()
	{
		return myBlockNotifier;
	}

	private class MyBlockNotifier implements BlockNotifier, java.io.Serializable
	{
	    /**
	     * Change this if we change its structure... not like it has any.
	     */
	    private static final long serialVersionUID = 5L;

		public void blockedBy(Vehicle by)
		{
			iVehicle = by;
			logger.info(String.format("%s blocked by %s... entering", PlayerCharacter.this, by));
			
			getIn(iVehicle);
		}

		public void blockedBy(Character by)
		{
			iCharacter = by;
			logger.info(String.format("%s blocked by %s... iCharacter set", PlayerCharacter.this, by));
			notifyO();
		}

		public void blockedBy(Item by)
		{
			/* do nothing */
		}

		public void blockedBy(Terrain by)
		{
			/* do nothing */
		}

		public void blockedBy(Projectile by)
		{
			/* TODO lol die? */
		}
	}

	public void dieAction()
	{
		move(getTile().getMap().getStartingTile());
		notifyO();
	}
	
	protected void leaveTile()
	{
		stopInteracting();
		
		super.leaveTile();
	}
}
